package com.amigo.online.provider.sync.util;

import java.util.BitSet;

/**
 * 布隆过滤器
 *
 * @author amigo
 */
public class BloomFilter {
    private static final int DEFAULT_SIZE = 2 << 24;
    private static final int[] SEEDS = {};
    private static BitSet bits = new BitSet(DEFAULT_SIZE);
    private static SimpleHash[] func = new SimpleHash[SEEDS.length];

    public static void addValue(String value) {
        for (SimpleHash f : func) {
            bits.set(f.hash(value), true);
        }
    }

    public static void add(String value) {
        if (value != null) {
            addValue(value);
        }
    }

    public static boolean contains(String value) {
        if (value == null) {
            return false;
        }
        boolean ret = true;
        for (SimpleHash f : func) {
            ret = ret && bits.get(f.hash(value));
        }
        return ret;
    }
}
